<?php
	$panngan2 = $_REQUEST["panngan2"];
	$panngan3 = $_REQUEST["panngan3"];
?>

<script type="text/javascript">
	$(document).ready(function(){

		//$.post('dropdown.php', {  tablename: 'tbl_creditor', dd: 'dd_payfor', idname: 'id' , fieldname: 'name' }, function(data) { $("#payfor").html(data); } );
		
		$.post('dropdown.php', {  tablename: 'expenses_lvl1', dd: 'ex1_id', idname: 'expenses1_id', fieldname: 'expenses1_name', by: '04,05' }, function(data) { $("#expenses1").html(data); } );



		$("input,select,textarea").not("[type=submit]").jqBootstrapValidation({
			submitSuccess: function ($form, event) { 
				//event.preventDefault();

				//alert("success");

			}
		});

		$( "#panngan2" ).change(function() {
			var panngan2= $(this).val();
			var panngan3 = "<?php echo $panngan3; ?>";
			
			//alert(panngan2);
			
			if (panngan2 != "") {
				//alert(panngan2);
				$.post('dd_panngan.php', {  panngan2: panngan2, panngan3: panngan3}, function(data) { 
					$("#dd_panngan3").html(data); 
						//alert(data);
					} );
			}
			
			

		});

		$("#month_year").datepicker({

			dateFormat: "yy-mm"
			//defaultDate: new Date()
			//showMonthAfterYear:true,
			
		});
		
		//$('#panngan2').trigger('change');
		
	
		
	}); //(document).ready

	
</script>
<form id="frm_petition_welfare" name="frm_petition_welfare" method="post" action="index.php" novalidate="">
	<input type="hidden" name="pages" value="submit_petition_welfare">
	<input type="hidden" name="pageid" value="1">
	<div class="row-fluid">
		<div class="control-group span2">
			<label class="control-label" for="budget_year">ปีงบประมาณ</label>
			<div class="controls ">
				<select class="span12" id="budget_year" name="budget_year" readonly>
					<option>2556</option>
					<option>2557</option>
					<option>2558</option>
					<option>2559</option>
					<option>2560</option>
				</select>
			</div>
		</div>

		<div class="control-group span5">
			<label class="control-label" for="panngan">แผนงาน</label>
			<div class="controls ">
				<select class="span12" id="panngan2" name="panngan2" required>
					<option value="">เลือก...</option>
				<?php
					require_once("includes/connect.php");
					require_once("includes/function.php");

					$db = NEW myDBS;
					$db->selectDB("hr_udoncity");
					
					$sql = "SELECT DISTINCT panngan2_id 
								FROM position 
								WHERE lvl_id like '" .$_SESSION["lvl1_id"]. "%'
								AND panngan2_id IS NOT NULL"
								; 

					//echo $sql;

					$result = $db->runSQL($sql);
					
					while($rows = $db->fetch_object ( $result )){
						$db->selectDB("account");
						$sql = "SELECT DISTINCT * FROM panngan2 WHERE panngan2_id = '" .$rows->panngan2_id. "'";
						$result1 = $db->runSQL($sql);
						while($rows1 = $db->fetch_object ( $result1 )){
							if ($rows1->panngan2_id == $panngan2) {
								$selected = " selected";
							}
							echo "<option value='".$rows1->panngan2_id."' $selected>$rows1->panngan2_name</option>";
						}

					
					}

				?>
				</select>
			</div>
		</div><!--/span-->

		<div class="control-group span5">
			<label class="control-label" for="panngan3">งาน</label>
			<div class="controls " id="dd_panngan3">
				<select class="span12" id="panngan3" name="panngan3">
					<option value="">เลือก</option>

				</select>
			</div>
		</div><!--/span-->
	</div><!--/row-fluid-->
	<div class="row-fluid">
		<div class="control-group span4">
			<label class="control-label" for="expenses1_name">หมวด / ลักษณะ</label>
			<div id="expenses1" class="controls">
				<select class="span12" id="ex1_id" name="ex1_id" required>
					<option value="">เลือก...</option>
				</select>
            </div>
		</div>

		<div class="control-group span4">
			<label class="control-label" for="expenses2_name">ประเภท</label>
			<div id="expenses2" class="controls">
				<select class="span12" id="ex2_id" name="ex2_id" required>
					<option value="">เลือก...</option>
				</select>
            </div>
		</div>

		<div class="control-group span4">
			<label class="control-label" for="expenses3_name">รายการ</label>
			<div id="expenses3" class="controls">
				<select class="span12" id="ex3_id" name="ex3_id" required>
					<option value="">เลือก...</option>
				</select>
            </div>
		</div>
	</div><!--/row-fluid-->
	<div class="row-fluid">
		<div class="control-group span4">
			<label class="control-label" for="month_year">เดือน/ปี</label>
			<div class="controls">
				<input class="span12" type="text" id="month_year" name="month_year"  />
            </div>
		</div>

		<div class="control-group span4">
			<label class="control-label" for="month_year">เลขที่ผู้เบิก</label>
			<div class="controls">
				<input class="span12" type="text" id="pet_id" name="pet_id"  readonly/>
            </div>
		</div>

		<div class="control-group span4">
			<label class="control-label" for="blank">&nbsp;</label>
			<button type="submit" id="submit" class="btn btn-primary"><i class="icon-ok icon-white"></i> เบิกฎีกาสวัสดิการ</button>
			<a href="index.php?pages=home" role="button" class="btn"><i class="icon-remove"></i>ยกเลิก</a>
		</div>

	</div><!--/row-fluid-->
	
	<p class="pull-right">
	</p>

</form> 
